<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Chain payload transform | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'transform-chain.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/transform-chain.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/transform-chain.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/transform-chain.html" rel="nofollow" target="_blank">../en/transform-chain.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="xpack-alerting.html">Alerting on cluster and index events</a></span>
»
<span class="breadcrumb-link"><a href="transform.html">Payload transforms</a></span>
»
<span class="breadcrumb-node">Chain payload transform</span>
</div>
<div class="navheader">
<span class="prev">
<a href="transform-script.html">« Script payload transform</a>
</span>
<span class="next">
<a href="api-java.html">Java API »</a>
</span>
</div>
<div class="section xpack">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="transform-chain"></a>Chain payload transform<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/x-pack/docs/en/watcher/transform/chain.asciidoc">edit</a><a class="xpack_tag" href="https://www.elastic.co/subscriptions"></a>
</h2>
</div></div></div>
<p>A <a class="xref" href="transform.html" title="Payload transforms">payload transform</a> that executes an ordered list of configured
payload transforms in a chain, where the output of one transform serves as the
input of the next transform in the chain. The payload that is accepted by this
transform serves as the input of the first transform in the chain and the output
of the last transform in the chain is the output of the <code class="literal">chain</code> transform as a
whole.</p>
<p>You can use chain payload transforms to build more complex transforms out of
the other available transforms. For example, you can combine a
<a class="xref" href="transform-search.html" title="Search payload transform"><code class="literal">search</code></a> payload transform and a
<a class="xref" href="transform-script.html" title="Script payload transform"><code class="literal">script</code></a> payload transform, as shown in the following snippet:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">"transform" : {
  "chain" : [ <a id="CO534-1"></a><i class="conum" data-value="1"></i>
    {
      "search" : {  <a id="CO534-2"></a><i class="conum" data-value="2"></i>
        "indices" : [ "logstash-*" ],
        "body" : {
          "size" : 0,
          "query" : {
            "match" : { "priority" : "error" }
          }
        }
      }
    },
    {
      "script" : "return [ error_count : ctx.payload.hits.total.value ]"  <a id="CO534-3"></a><i class="conum" data-value="3"></i>
    }
  ]
}</pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO534-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>The <code class="literal">chain</code> payload transform definition</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO534-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>The first transform in the chain (in this case, a <code class="literal">search</code> payload transform)</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO534-3"><i class="conum" data-value="3"></i></a></p>
</td>
<td align="left" valign="top">
<p>The second and final transform in the chain (in this case, a <code class="literal">script</code>
payload transform)</p>
</td>
</tr>
</table>
</div>
<p>This example executes a <code class="literal">count</code> search on the cluster to look for <code class="literal">error</code> events.
The search results are then passed to the second <code class="literal">script</code> payload transform.
The <code class="literal">script</code> payload transform extracts the total hit count and assigns it to
the <code class="literal">error_count</code> field in a newly-generated payload. This new payload is the
output of the <code class="literal">chain</code> payload transform and replaces the payload in the watch
execution context.</p>
</div>
<div class="navfooter">
<span class="prev">
<a href="transform-script.html">« Script payload transform</a>
</span>
<span class="next">
<a href="api-java.html">Java API »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>